package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.entity.BaseTrademark;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author tangsy
 * @Description TODO
 * @date 2022/11/30 17:06
 * @Version 1.0
 */
@Api(tags = "品牌管理")
@RestController
@RequestMapping("admin/product")
public class BaseTrademarkController {

    @Autowired
    BaseTrademarkService baseTrademarkService;

    //api.gmall.com/admin/product/baseTrademark/{page}/{limit}
    @ApiOperation("分页获取品牌属性")
    @GetMapping("baseTrademark/{pn}/{ps}")
    public Result baseTrademark(@PathVariable("pn") Long pn,
                                @PathVariable("ps") Long ps){
        Page<BaseTrademark> pageList = new Page<>(pn,ps);
        Page<BaseTrademark> result = baseTrademarkService.page(pageList);
        return Result.ok(result);
    }

    //api.gmall.com/admin/product/baseTrademark/save
    @ApiOperation("添加品牌数据")
    @PostMapping("baseTrademark/save")
    public Result save(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.save(baseTrademark);
        return Result.ok();
    }

    //api.gmall.com/admin/product/baseTrademark/remove/{id}
    @ApiOperation("删除品牌")
    @DeleteMapping("baseTrademark/remove/{id}")
    public Result remove(@PathVariable("id") Long id){
        baseTrademarkService.removeById(id);
        return Result.ok();
    }

    //api.gmall.com/admin/product/baseTrademark/get/{id}
    @ApiOperation("根据id获取品牌信息")
    @GetMapping("baseTrademark/get/{id}")
    public Result getBaseTrademark(@PathVariable("id") Long id){
        BaseTrademark baseTrademark = baseTrademarkService.getById(id);
        return Result.ok(baseTrademark);
    }

    //api.gmall.com/admin/product/baseTrademark/update
    @ApiOperation("修改品牌")
    @PutMapping("baseTrademark/update")
    public Result update(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.updateById(baseTrademark);
        return Result.ok();
    }

    //admin/product/baseTrademark/getTrademarkList
    @ApiOperation("获取品牌信息")
    @GetMapping("/baseTrademark/getTrademarkList")
    public Result getTrademarkList(){
        List<BaseTrademark> list = baseTrademarkService.list();
        return Result.ok(list);
    }
}
